package com.bigData.main.mapper;

import com.bigData.main.pojo.Car;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CarMapper {

    @Insert("insert into  car(cname, color, price, storage, time, status, creator) values(#{cname}, #{color}, #{price},#{storage}, NOW() ,#{status} ,#{creator} )")
    Integer insertCar(Car car);

    @Insert("insert into  car(cname, color, price, status) values(#{cname}, #{color}, #{price}, #{status})")
    Integer insertCarField(Car car);

    @Insert("insert into  car(cname, color, price, storage, time, status, creator) values(#{cname}, #{color}, #{price},#{storage}, NOW() ,#{status} ,#{creator} )")
    Integer insertCarAll(Car car);

    @Select("select * from  car")
    List<Car> selectAllCar();

    //查看车辆
    @Select("SELECT * FROM  car WHERE cid = #{cids}")
    List<Car> selectCarById(@Param("cids") int cids);

    @Update("update  car set cname=#{cname}, color=#{color}, price=#{price}, storage=#{storage}, time=NOW(),status=#{status}, creator={creator}  where cid=#{cid}")
    Integer updateCar(Car car);

    @Update("update  car set status= '已售出' where cid=#{cid}")
    Integer updateCarStatus(int cid);


    @Delete("delete from  car where cid=#{cid}")
    Integer deleteCar(int cid);  // 删除指定ID的车辆

    // 查询已售出车辆
    @Select("SELECT * FROM  car WHERE status = '已售出'")
    List<Car> selectSoldCars();

    // 查询未售出车辆
    @Select("SELECT * FROM  car WHERE status = '未售出'")
    List<Car> selectUnsoldCars();

    @Select("SELECT COUNT(*) FROM   car WHERE status = '已售出';")
    Integer allCar();

    @Select("SELECT COUNT(*) FROM   car WHERE status = '未售出';")
    Integer alluCar();

    @Select("SELECT COUNT(*) FROM   car WHERE creator = #{creator};")
    Integer countCreator(String creator);

    @Select("SELECT SUM(price) FROM  car")
    Integer allPrice();

    @Select("SELECT time, COUNT(*) AS count  FROM  car  WHERE status ='已售出' GROUP BY time;")
    Integer timeCount();

}